package com.zhongkai.controller;

import com.zhongkai.app.service.WarehouseService;
import com.zhongkai.model.utils.TTHelp;
import com.zhongkai.model.utils.ZhongkaiResult;
import com.zhongkai.model3.Chinaset;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * 库存管理
 * */

@Controller
public class WarehouseController {

    @Autowired
    private WarehouseService warehouseService;


    /**
     * 工程库存添加
     *
     * @param war_name  库存物料名称
     * @param war_count 数量
     */
    @RequestMapping(value = "/warehouse/add", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult addWarehouse(String war_name, Integer war_count,HttpServletRequest httpServletRequest) {

        String war_uuid = TTHelp.generate();
        Chinaset chinaset = (Chinaset) httpServletRequest.getAttribute("user");
        ZhongkaiResult result = warehouseService.addWarehouse(chinaset.getSetName(),chinaset.getUuid(),war_name,war_count,war_uuid);

        return result;
    }


    /**
     * 工程库存增加数量
     *
     * @param war_name  库存物料名称
     * @param war_count 数量
     * @param war_uuid  产品uuid
     * @param war_ps    备注
     */
    @RequestMapping(value = "/warehouse/put", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult putWarehouse(String war_name, @RequestParam(defaultValue = "0")Integer war_count,String war_uuid,String war_ps,HttpServletRequest httpServletRequest) {

        Chinaset chinaset = (Chinaset) httpServletRequest.getAttribute("user");
        ZhongkaiResult result = warehouseService.putWarehouse(chinaset.getUuid(),chinaset.getSetName(),war_name,war_count,war_uuid,war_ps);

        return result;
    }



    /**
     * 工程库存减少
     *
     * @param war_name  库存物料名称
     * @param war_count 数量
     * @param war_uuid  产品uuid
     * @param war_ps    备注
     */
    @RequestMapping(value = "/warehouse/out", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult outWarehouse(String war_name, @RequestParam(defaultValue = "0")Integer war_count,String war_uuid,String war_ps,HttpServletRequest httpServletRequest) {

        Chinaset chinaset = (Chinaset) httpServletRequest.getAttribute("user");
        ZhongkaiResult result = warehouseService.outWarehouse(chinaset.getUuid(),chinaset.getSetName(),war_name,war_count,war_uuid,war_ps);

        return result;
    }



    /**
     * 删除库存
     *
     * @param war_name  库存物料名称
     * @param war_uuid  产品uuid
     */
    @RequestMapping(value = "/warehouse/remove", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult removeWarehouse(String war_name, String war_uuid,HttpServletRequest httpServletRequest) {

        Chinaset chinaset = (Chinaset) httpServletRequest.getAttribute("user");
        ZhongkaiResult result = warehouseService.removeWarehouse(chinaset.getUuid(),chinaset.getSetName(),war_name,war_uuid);

        return result;
    }


    /**
     * 库存列表
     */
    @RequestMapping(value = "/warehouse/list", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult listWarehouse(Integer page, Integer rows) {

        ZhongkaiResult result = warehouseService.listWarehouse(page,rows);

        return result;
    }







    //----------------------------------------办公库存----------------------------------------


    /**
     * 工程库存添加
     *

     * @param war_name  库存物料名称
     * @param war_count 数量
     */
    @RequestMapping(value = "/warehouse/add2", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult addWarehouse2(String war_name, Integer war_count,HttpServletRequest httpServletRequest) {

        String war_uuid = TTHelp.generate();
        Chinaset chinaset = (Chinaset) httpServletRequest.getAttribute("user");
        ZhongkaiResult result = warehouseService.addWarehouse2(chinaset.getSetName(),chinaset.getUuid(),war_name,war_count,war_uuid);

        return result;
    }


    /**
     * 工程库存增加
     *

     * @param war_name  库存物料名称
     * @param war_count 数量
     * @param war_uuid  产品uuid
     * @param war_ps    备注
     */
    @RequestMapping(value = "/warehouse/put2", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult putWarehouse2(String war_name, @RequestParam(defaultValue = "0")Integer war_count,String war_uuid,String war_ps,HttpServletRequest httpServletRequest) {

        Chinaset chinaset = (Chinaset) httpServletRequest.getAttribute("user");
        ZhongkaiResult result = warehouseService.putWarehouse2(chinaset.getUuid(),chinaset.getSetName(),war_name,war_count,war_uuid,war_ps);

        return result;
    }



    /**
     * 工程库存减少
     *
     * @param war_name  库存物料名称
     * @param war_count 数量
     * @param war_uuid  产品uuid
     * @param war_ps    备注
     */
    @RequestMapping(value = "/warehouse/out2", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult outWarehouse2(String war_name, @RequestParam(defaultValue = "0")Integer war_count,String war_uuid,String war_ps,HttpServletRequest httpServletRequest) {

        Chinaset chinaset = (Chinaset) httpServletRequest.getAttribute("user");
        ZhongkaiResult result = warehouseService.outWarehouse2(chinaset.getUuid(),chinaset.getSetName(),war_name,war_count,war_uuid,war_ps);

        return result;
    }



    /**
     * 删除库存
     *
     * @param war_name  库存物料名称
     * @param war_uuid  产品uuid
     */
    @RequestMapping(value = "/warehouse/remove2", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult removeWarehouse2(String war_name, String war_uuid,HttpServletRequest httpServletRequest) {

        Chinaset chinaset = (Chinaset) httpServletRequest.getAttribute("user");
        ZhongkaiResult result = warehouseService.removeWarehouse2(chinaset.getUuid(),chinaset.getSetName(),war_name,war_uuid);

        return result;
    }


    /**
     * 库存列表
     */
    @RequestMapping(value = "/warehouse/list2", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult listWarehouse2(Integer page, Integer rows) {

        ZhongkaiResult result = warehouseService.listWarehouse2(page,rows);

        return result;
    }




    //----------------------------------------产品库存----------------------------------------


    /**
     * 工程库存添加
     *

     * @param war_name  库存物料名称
     * @param war_count 数量
     */
    @RequestMapping(value = "/warehouse/add3", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult addWarehouse3(String war_name, Integer war_count,HttpServletRequest httpServletRequest) {

        String war_uuid = TTHelp.generate();
        Chinaset chinaset = (Chinaset) httpServletRequest.getAttribute("user");
        ZhongkaiResult result = warehouseService.addWarehouse3(chinaset.getSetName(),chinaset.getUuid(),war_name,war_count,war_uuid);

        return result;
    }


    /**
     * 工程库存增加
     *

     * @param war_name  库存物料名称
     * @param war_count 数量
     * @param war_uuid  产品uuid
     * @param war_ps    备注
     */
    @RequestMapping(value = "/warehouse/put3", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult putWarehouse3(String war_name, @RequestParam(defaultValue = "0")Integer war_count,String war_uuid,String war_ps,HttpServletRequest httpServletRequest) {

        Chinaset chinaset = (Chinaset) httpServletRequest.getAttribute("user");
        ZhongkaiResult result = warehouseService.putWarehouse3(chinaset.getUuid(),chinaset.getSetName(),war_name,war_count,war_uuid,war_ps);

        return result;
    }



    /**
     * 工程库存减少
     *
     * @param war_name  库存物料名称
     * @param war_count 数量
     * @param war_uuid  产品uuid
     * @param war_ps    备注
     */
    @RequestMapping(value = "/warehouse/out3", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult outWarehouse3(String war_name, @RequestParam(defaultValue = "0")Integer war_count,String war_uuid,String war_ps,HttpServletRequest httpServletRequest) {

        Chinaset chinaset = (Chinaset) httpServletRequest.getAttribute("user");
        ZhongkaiResult result = warehouseService.outWarehouse3(chinaset.getUuid(),chinaset.getSetName(),war_name,war_count,war_uuid,war_ps);

        return result;
    }



    /**
     * 删除库存
     *
     * @param war_name  库存物料名称
     * @param war_uuid  产品uuid
     */
    @RequestMapping(value = "/warehouse/remove3", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult removeWarehouse3(String war_name, String war_uuid,HttpServletRequest httpServletRequest) {

        Chinaset chinaset = (Chinaset) httpServletRequest.getAttribute("user");
        ZhongkaiResult result = warehouseService.removeWarehouse3(chinaset.getUuid(),chinaset.getSetName(),war_name,war_uuid);

        return result;
    }


    /**
     * 库存列表
     */
    @RequestMapping(value = "/warehouse/list3", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult listWarehouse3(Integer page, Integer rows) {

        ZhongkaiResult result = warehouseService.listWarehouse3(page,rows);

        return result;
    }


    /**
     * 库存柱状图 / 饼状图 数据一样的.........
     *
     * @param status 类型 //1工程 2办公 3公司产品
     */
    @RequestMapping(value = "/warehouse/analyze", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult analyze(String status) {

        ZhongkaiResult result = warehouseService.analyze(status);

        return result;
    }
}
